<!-- App.vue -->
<template>
  <div id="app">
    <!-- 添加全局导航栏 -->
    <div v-if="isAuthenticated" class="navbar">
      <router-link to="/welcome">首页</router-link> |
      <router-link to="/management">管理</router-link> |
      <router-link to="/query">查询</router-link> |
      <router-link to="/profile">个人中心</router-link> |
      <a href="#" @click.prevent="logout">退出登录</a>
    </div>
    
    <router-view />
  </div>
</template>

<script>
export default {
  name: 'App',
  computed: {
    isAuthenticated() {
      return localStorage.getItem('token') !== null;
    }
  },
  methods: {
    logout() {
      // 清除 token
      localStorage.removeItem('token');
      // 跳转到登录页
      this.$router.push({ name: 'Login' });
    }
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}

.navbar {
  background-color: #f8f9fa;
  padding: 10px;
  margin-bottom: 20px;
}

.navbar a {
  margin: 0 10px;
  text-decoration: none;
  color: #333;
}

.navbar a:hover {
  color: #007bff;
}
</style>